<%--<%@ page contentType='text/html; charset=UTF-8' %>--%>
<%@ page import='java.sql.ResultSet' %>
<%@ page import='forum.*' %>
<%@taglib uri="/WEB-INF/tlds/label.tld" prefix="lutag" %>

<%
    String sessionUsername = (String)session.getAttribute("username");
    String sessionType = (String)session.getAttribute("type");
    String forum_id = request.getParameter("forum_id");
%>
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">

<html>
<head>
<title><lutag:label name="readthread"/></title>
<link rel="stylesheet" href="./css/forum.css" type="text/css">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <script src="../editor/kindeditor.js"></script>
      <script>
        KE.show({
                id : 'myarea'
        });
	  </script>
</head>
<jsp:include page="./include/body.jsp" flush="true" />

	<table width="100%" height="20" border="0" cellpadding="1" cellspacing="1">
		<tr> 
			<td height="20" valign="top" class="pathBar">
				<a href="./index.jsp" class="pathBarLink"><%= Variable.getForumName() %></a><span class="pathBarSeperator"> > </span>
				<a href="./index.jsp?page=thread&forum_id=<%= forum_id %>" class="pathBarLink"><%= Utilities.getforumTile(forum_id) %></a>
			</td>
		</tr>
	</table>
	<table cellspacing="0" cellpadding="0" width="100%" class="table_bg" border="0" align="center">
<tr>
<td>
<table cellspacing="1" cellpadding="4" width="100%" border="0">
<tr class="tr_bg">
    <td align="middle" colspan="1" class="tr_bg">
<span class="span_style">
<b><lutag:label name="topictitle"/></b>
</span>
</td>
<td align="middle" colspan="1" class="tr_bg">
<span class="span_style">
<b><lutag:label name="topicstart"/></b>
</span>
</td>
    <td align="middle" colspan="1" class="tr_bg">
<span class="span_style">
<b><lutag:label name="poston"/></b>
</span>
</td>
    <td align="middle" colspan="1" class="tr_bg">
<span class="span_style">
<b><lutag:label name="replies"/></b>
</span>
</td>
    <td align="middle" colspan="1" class="tr_bg">
<span class="span_style">
<b><lutag:label name="views"/></b>
</span>
</td>
    <td align="middle" colspan="1" class="tr_bg">
<span class="span_style">
<b><lutag:label name="lastaction"/></b>
</span>
</td>   	    	                   
	<% if(sessionType.equals("Admin")){ %>
    <td align="middle" colspan="1" class="tr_bg">
<span class="span_style">
<b><lutag:label name="delmsg"/></b>
</span>
</td>
	<% } %>	 

	<%
	DBConnectie db = new DBConnectie(Variable.getDb(),Variable.getDbLogin(),Variable.getDbPassword());
			
	db.connect();

	ResultSet rs = db.selectQuery("SELECT DISTINCT thread_id FROM forum_message WHERE forum_id=\""+ forum_id +"\" ORDER BY thread_id DESC");

	while(rs.next()){
		String thread_id = rs.getString("thread_id");
				
		ResultSet rs2 = db.selectQuery(
			"SELECT * "+
			"FROM forum_message "+
			"WHERE forum_id=\"" + forum_id + "\" " + 
			"AND thread_id=\""+ thread_id + "\" " +
			"AND reply_id =\"0\"");
								
		while(rs2.next()){
			String title = Utilities.getThreadTile(forum_id,thread_id);
			String user = rs2.getString("user");
			String date_time = rs2.getString("date_time");
	%>
	<tr bgcolor="#ffffff">
	<td align="left" valign="top" width="0">
<span class="span_style">
			<a href="./index.jsp?page=message&forum_id=<%= forum_id %>&thread_id=<%= thread_id %>&start=0"><%= title %></a><%= Utilities.getMorePages(Utilities.getReplies(forum_id,thread_id),forum_id,thread_id,true) %>
			</span>
			</td>
			<td align="left" valign="top" width="0">
<span class="span_style">
			<%= user %>	
			<td align="left" valign="top" width="0">
<span class="span_style">
			<%= date_time %>	
			<td align="left" valign="top" width="0">
<span class="span_style">						
			<%= Utilities.getReplies(forum_id,thread_id) %>								
			<td align="left" valign="top" width="0">
<span class="span_style">
			<%= Utilities.getViews(forum_id,thread_id) %>
			<td align="left" valign="top" width="0">
<span class="span_style">
			<%= Utilities.lastActionInfo(forum_id,thread_id) %>
										
			<% if(sessionType.equals("Admin")){ %>
		<td align="left" valign="top" width="0">
<span class="span_style">
				<a href="../servlet/Thread.delete?forum_id=<%= forum_id %>&thread_id=<%= thread_id %>">Delete</a>
			<% } %>
		<% } %>
	<% } %>
</span>
</td>
</tr>
	<%		
		ResultSet rs3 = db.selectQuery(
			"SELECT MAX(thread_id) thread_id FROM forum_threads");
						
		String lastThread_id = "null";
		while(rs3.next()){
			lastThread_id = rs3.getString("thread_id");
						
			if(lastThread_id == null){
				lastThread_id = "-1";
			}
		}
		
		db.close();       	    
	%>							

	<tr class="table_bg">
 <td align="left" colspan="7" class="tr_bg">
<span class="span_style">
<b><a href="./index.jsp"><lutag:label name="back"/></a></b>
</span>
</td>
</table>
</td>
</tr>
</table>
	<br>
	<table cellspacing="0" cellpadding="0" width="100%" class="table_bg" border="0" align="center">
<tr>
<td>
<table cellspacing="1" cellpadding="4" width="100%" border="0">
<tr class="tr_bg">
    <td align="left" colspan="3" class="tr_bg">
<span class="span_style">
<b><lutag:label name="addthread"/></b>
</span>
</td>
</tr>
	<tr bgcolor="#ffffff">
    <td align="left" valign="top" width="200">
<span class="span_style">
	<form action="../servlet/Thread.add" method="POST" name="formmessage">
	<input type="hidden" name="forum_id" value="<%= forum_id %>">
	<input type="hidden" name="lastThread_id" value="<%= lastThread_id %>">
	<input type="hidden" name="user" value="<%= sessionUsername %>">
	<lutag:label name="str_title"/><lutag:label name="colon"/><br>
	<input type="text" name="title" size="62" maxlength="60"><br>
	<lutag:label name="str_msg"/><lutag:label name="colon"/><br>
	<textarea name="message" id="myarea"  cols="100" rows="10" style="width:700px;height:300px;"></textarea><br>
	<input type="submit" value='<lutag:label name="submit"/>'><br>
	</form>
	</span>
	</td>
</tr>
</table>
</td>
</tr>
</table>

<jsp:include page="./include/footer.jsp" flush="true" />